#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 5e5 + 5;

int n, m, root;
int a[N];
vector<int> ch[N];
int st[N][20], dep[N];
void dfs(int u, int fu) {
  st[u][0] = fu;
  dep[u] = dep[fu] + 1;
  for (int v : ch[u]) {
    if (v == fu) continue;
    dfs(v, u);
  }
}
void init_st() {
  rep(j, 1, 18) rep(i, 1, n) st[i][j] = st[st[i][j - 1]][j - 1];
}
int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  int d = dep[u] - dep[v];
  per(j, 18, 0) {
    if (d & (1 << j)) u = st[u][j];
  }
  if (u == v) return u;
  per(j, 18, 0) {
    if (st[u][j] != st[v][j]) u = st[u][j], v = st[v][j];
  }
  return st[u][0];
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m >> root;
  rep(i, 2, n) {
    int u, v;
    cin >> u >> v;
    ch[u].push_back(v);
    ch[v].push_back(u);
  }
  dfs(root, 0);
  init_st();
  rep(i, 1, m) {
    int u, v;
    cin >> u >> v;
    cout << lca(u, v) << endl;
  }
  return 0;
}